package cloud.maque.module.system.service.impl;

import cloud.maque.module.system.entity.SysUserPost;
import cloud.maque.module.system.mapper.UserPostMapper;
import cloud.maque.module.system.service.UserPostService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserPostServiceImpl extends ServiceImpl<UserPostMapper, SysUserPost> implements UserPostService {
    @Override
    public List<SysUserPost> GetList(SysUserPost data) {
        QueryWrapper<SysUserPost> query = new QueryWrapper<>();
        if (!StrUtil.isEmptyIfStr(data.getPostId())) {
            query.lambda().eq(SysUserPost::getPostId, data.getPostId());
        }
        if (!StrUtil.isEmptyIfStr(data.getUserId())) {
            query.lambda().like(SysUserPost::getUserId, data.getUserId());
        }
        return this.list(query);
    }

    @Override
    public SysUserPost SaveUserPost(SysUserPost data) {
        this.saveOrUpdate(data);
        return data;
    }

    @Override
    public Boolean DeleteByPostId(String postId) {
        QueryWrapper<SysUserPost> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysUserPost::getPostId, postId);
        return this.remove(queryWrapper);
    }

    @Override
    public Boolean DeleteByUserId(String userId) {
        QueryWrapper<SysUserPost> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysUserPost::getUserId, userId);
        return this.remove(queryWrapper);
    }
}
